package com.jindun.paper.ui.user;

import org.apache.commons.lang.StringUtils;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;

import com.jindun.paper.model.Users;

public class UserListViewFilter extends ViewerFilter {

	private String searchString;

	public void setSearchText(String s) {
		// ensure that the value can be used for matching
		this.searchString = ".*" + s + ".*";
	}

	@Override
	public boolean select(Viewer viewer, Object parentElement, Object element) {

		Users clientVo = (Users) element;
		if (searchString == null || searchString.length() == 0) {
			return true;
		}
		return StringUtils.isNotBlank(clientVo.getName()) && clientVo.getName().matches(this.searchString) ||
				StringUtils.isNotBlank(clientVo.getUsername()) && clientVo.getUsername().matches(this.searchString) ||
				StringUtils.isNotBlank(clientVo.getRole()) && clientVo.getRole().matches(searchString);
	}

}
